//
//  RBMyCouponListCell.m
//  zhongzhenglu
//
//  Created by XL on 2022/8/3.
//

#import "RBMyCouponListCell.h"
#import "UIView+RBAdd.h"
#import "UIScrollView+RBAdd.h"
#import <Masonry.h>
#import "RBThemeConfig.h"
#import <UIColor+YYAdd.h>
#import <UIView+YYAdd.h>
#import "UIButton+RBAdd.h"
#import "RBDefine.h"

@interface RBMyCouponListCell()

@property(nonatomic, strong)IBOutlet UIImageView *bgImgView;
@property(nonatomic, strong)IBOutlet UILabel *amountL;
@property(nonatomic, strong)IBOutlet UILabel *titleL;
@property(nonatomic, strong)IBOutlet UILabel *desL;
@property(nonatomic, strong)IBOutlet UIButton *useBtn;

@property(nonatomic, strong) RBCellModel *cellModel;

@end

@implementation RBMyCouponListCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self zoomSubViewsWithSelf];
}

- (void)setCellModel:(RBCellModel *)cellModel
{
    _cellModel = cellModel;
    if([cellModel.cellData isKindOfClass:RBMyCouponModel.class])
    {
        RBMyCouponModel *model = cellModel.cellData;
        if(model.coupon_class.intValue == 2)
        {
            self.amountL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(33)] color:[UIColor colorWithHexString:@"518CFF"] string:model.price];
            }];
        }
        else
        {
            self.amountL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(20)] color:[UIColor colorWithHexString:@"518CFF"] string:@"¥"];
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(46)] color:[UIColor colorWithHexString:@"518CFF"] string:model.price];
            }];
        }
        self.amountL.textAlignment = NSTextAlignmentCenter;
        self.amountL.adjustsFontSizeToFitWidth = YES;
        self.titleL.text = model.coupon_name;
        self.desL.text = model.coupon_desc;
        self.useBtn.backgroundColor = [UIColor colorWithHexString:[model.status_style isEqualToString:@"blue"]? @"#518CFF": @"#C2C2C2"];
        [self.useBtn rbSetTitle:model.status];
    }
    else if([cellModel.cellData isKindOfClass:RBConfirmOrderCouponModel.class])
    {
        RBConfirmOrderCouponModel *model = cellModel.cellData;
        if(model.coupon_class == 2)
        {
            self.amountL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(33)] color:[UIColor colorWithHexString:@"518CFF"] string:[NSString stringWithFormat:@"%@折", model.coupon_zhekou]];
            }];
        }
        else
        {
            self.amountL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(20)] color:[UIColor colorWithHexString:@"518CFF"] string:@"¥"];
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(46)] color:[UIColor colorWithHexString:@"518CFF"] string:model.coupon_price];
            }];
        }
        self.amountL.textAlignment = NSTextAlignmentCenter;
        self.amountL.adjustsFontSizeToFitWidth = YES;
        self.titleL.text = model.coupon_class == 2? @"折扣券": @"满减券";
        self.desL.text = model.coupon_man_price.floatValue == 0? @"无限制": [NSString stringWithFormat:@"满%@可用", model.coupon_man_price];
        self.useBtn.hidden = YES;
//        self.useBtn.backgroundColor = [UIColor colorWithHexString:[model.status_style isEqualToString:@"blue"]? @"#518CFF": @"#C2C2C2"];
//        [self.useBtn rbSetTitle:model.status];
    }
}

#pragma mark - Event

- (IBAction)userBtnTapped:(id)sender
{
    if(self.cellModel.eventBlock1)
    {
        self.cellModel.eventBlock1(0, 0, self.cellModel.cellData);
    }
}

@end
